// voiceringup.cpp : Defines the entry point for the console application.
//
#include "targetver.h"
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <stdlib.h>

#include "Endpoint/Skype/SkypeCommWindow.h"
#include "Endpoint/Skype/TCPServer.h"
#include "Endpoint/Skype/CallCommand.h"
//
int skypeConnect() {
	SkypeCommWindow scw;
	switch(scw.connectToSkype(30))
	{
	case SkypeCommWindow::OK:
		_tprintf(TEXT("{%s}\n"), TEXT("CONNECTED TO SKYPE"));
		//scw.sendCommand(SkypeCommand(TEXT("call echo123")));
		break;
	case SkypeCommWindow::CantConnectToSkype:
		_tprintf(TEXT("{%s}\n"), TEXT("CAN'T CONNECT TO SKYPE"));
		break;
	case SkypeCommWindow::TimedOut:
		_tprintf(TEXT("{%s}\n"), TEXT("TIMED OUT"));
		break;
	default:
		break;
	}
	//for(;;) {
	//	if (scw.getQueue().wait()) {
	//		scw.getQueue().lock();
	//		while(!scw.getQueue().empty()) {
	//			_tprintf(TEXT("[%s]\n"), scw.getQueue().front().c_str());
 //                scw.getQueue().pop_front();
	//		}
	//		scw.getQueue().unlock();
	//	}
	//}
    CallCommand cmd(TEXT("+79086170923"));
    cmd.sendTo(scw);
	Sleep(300*1000);
	return 0;
}
//
class TcpHandler : public ITCPHandler {
public:
	virtual void processConnection(IConnection* connection) {
		char buf[1024];
		for(;;) {
		size_t szBuf = sizeof(buf) - 1;
		memset(buf, 0, sizeof(buf));
		if (connection->receive(buf, szBuf)) {
			buf[szBuf] = 0;
			printf("%d\n%s\n", szBuf, buf);
		}
		connection->send(buf, szBuf);
		}
	}
};
//
//int CALLBACK WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
int _tmain(int argc, char* argv[])
{
	/*TCPServer server(0, new TcpHandler());
	server.start();
	_tprintf(TEXT("port: %d\n"), server.getPort());*/
	skypeConnect();
	
}

